<!DOCTYPE HTML>
<html>
<head>
    <script src="../resources/testharness.js"></script>
    <script src="../resources/testharnessreport.js"></script>
</head>
<body>
<script>
    var t = async_test("Test that a preload with a crossorigin=use-credentials attribute loads the expected CORS enabled resources.");
    var credentialSpecificMarkupLoad = false;
    var credentialStarMarkupError = false;
    var credentialSpecificDynamicLoad = false;
    var credentialStarDynamicError = false;
</script>
<link crossorigin="use-credentials" rel="preload" as="fetch" href="http://localhost:8080/security/resources/abe-allow-credentials.php" onload="credentialSpecificMarkupLoad = true;">
<link crossorigin="use-credentials" rel="preload" as="fetch" href="http://localhost:8080/security/resources/abe-allow-star.php" onerror="credentialStarMarkupError = true;">
<script>
    var link = document.createElement("link");
    link.rel = "preload";
    link.as = "fetch";
    link.crossOrigin = "anonymous";
    link.addEventListener("load", function() { credentialSpecificDynamicLoad = true; });
    link.href = "http://localhost:8080/security/resources/abe-allow-credentials.php?1";
    document.body.appendChild(link);

    link = document.createElement("link");
    link.rel = "preload";
    link.as = "fetch";
    link.crossOrigin = "use-credentials";
    link.addEventListener("error", function() { credentialStarDynamicError = true; });
    link.href = "http://localhost:8080/security/resources/abe-allow-star.php?1";
    document.body.appendChild(link);
</script>
<script src="../resources/slow-script.pl?delay=500"></script>
<script>
    window.onload = t.step(function(){
        assert_true(credentialSpecificMarkupLoad, "credential specific markup resource triggered load event");
        assert_true(credentialStarMarkupError, "credential star markup resource triggered error event");
        assert_true(credentialSpecificDynamicLoad, "credential specific dynamic resource triggered load event");
        assert_true(credentialStarDynamicError, "credential star dynamic resource triggered error event");
        t.done();
    });
</script>
</body>
</html>
